package com.design.pattern.singleton;

/**
 * 普通的通过锁实现单例
 */
public class GeneralLockSingleton {
    /**
     * 构造方法私有化,防止直接new实例.
     */
    private GeneralLockSingleton(){}

    /**
     * 持有本类
     */
    private static GeneralLockSingleton instance;

    /**
     * 对外暴露的方法,返回单例实例(方法加锁)
     * @return 单例实例
     */
    public synchronized static GeneralLockSingleton getInstance(){
        if (null==instance){
            instance=new GeneralLockSingleton();
        }
        return instance;
    }
}
